<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>采购单退货管理</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${Plugins}/jquery/jquery-1.3.2.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/utils.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<style type="text/css">
#searchbar {
    margin-bottom: 10px;
    margin-left: 15px;
}
.navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
.l-button-search{
	width: 50px;
	margin-left: 10px;
	padding-bottom: 2px;
	display: inline;
}
</style>
</head>
<body style="padding:6px; overflow:hidden;">
<div id="">
	<div class="navbar"><span>您当前的位置：采购管理 &gt;采购退换货管理</span></div>
	<form action="#"  name="queryForm" id="queryForm" method="POST">
	  <div id="searchbar">
	  <br>
		 退货单号：<input type="text" id="puNo" name="puNo" size="18" maxLength="40" value="${purchaseOrderVo.puNo }">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		创建人：<input type="text" id="creater" name="creater" size="18" maxLength="40" value="${purchaseOrderVo.creater }">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		商品名称：<input type="text" id="commodityName" name="commodityName" size="18" maxLength="40" value="${purchaseOrderVo.commodityName }">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		退货单状态：<select id="status" name="status">
		            <option value=""  <c:if test="${purchaseOrderVo.status == -1}">selected</c:if>>请输入</option>
				    <option value="0"  <c:if test="${purchaseOrderVo.status == 0}">selected</c:if>>待审核</option>
				   	<option value="1"  <c:if test="${purchaseOrderVo.status == 1}">selected</c:if>>已审核</option>
				   	<option value="2"  <c:if test="${purchaseOrderVo.status == 2}">selected</c:if>>出库中</option>
				   	<option value="3"  <c:if test="${purchaseOrderVo.status == 3}">selected</c:if>>退货完成</option>
				   </select>&nbsp;&nbsp;&nbsp;&nbsp; 
		   <br><br>
		   
		<%-- <c:choose>
		  <c:when test="${role == 'PURCHASE_MAN'}">
			<input type="hidden" id="createPersonName" name="createPersonName" value="${poQueryVo.createPersonName }">
		  </c:when>
		  <c:otherwise>
		采购人员：<input type="text" id="createPerson" name="createPerson" size="18" maxLength="40" value="${poQueryVo.createPerson }">&nbsp;&nbsp;&nbsp;&nbsp;
		  </c:otherwise>
		</c:choose> --%>
		<input  type="submit" value="查询" class="l-button-search"  >&nbsp;&nbsp;&nbsp;&nbsp;<input  type="button" id="resetButton" value="重置" class="l-button-search" >
	  </div>  
	</form>
	<br/>
</div>
<div id="maingrid6" style="margin:0; padding:0"></div>
  <div style="display:none;">
  <!-- g data total ttt -->
</div>
<script type="text/javascript">
	var basePath='${BasePath}';
    var grid = null;
    $(function () {
    	$('#resetButton').click(function() {
        	$('#puNo').val('');
        	$('#creater').val('');
        	$('#createPersonName').val('');
        	$('#commodityName').val('');
        	$("select").find("option[value='']").attr("selected","true");  
        });
        grid = $("#maingrid6").ligerGrid({
            columns: [
            { display: '退货单号', name: 'puNo'},
            { display: '货品编号', name: 'prodNo'},
            { display: '商品名称', name: 'commodityName'},
            { display: '退换货状态', name: 'purType', render: function (rowdata, rowindex, value) {
            	if (value == 1) {
            		return '采购退货';
            	} else if (value == 2) {
            		return '采购换货';
            	}else {
            		return '';
            	}
            } },
            { display: '总退货价', name: 'totalPrice'},
            { display: '总退货数量', name: 'yieldAmountNumner'},
            { display: '供应商名称', name: 'supName'},
            { display: '仓库名称', name: 'purWhName'},
            { display: '创建时间', name: 'createTime'},
            { display: '最近审核人', name: 'lastAuditPerson'},
            { display: '退货单状态', name: 'status',render: function (rowdata, rowindex, value) {
            	if (value == 0) {
            		return '待审核';
            	} else if (value == 1) {
            		return '已审核';
            	} else if (value == 2) {
            		return '出库中';
            	} else if (value == 3) {
            		return '退货完成';
            	} else if (value == 4) {
            		return '换货入库';
            	} else if (value == 5) {
            		return '入库中';
            	} else if (value == 6) {
            		return '采购换货完成';
            	}  else {
            		return '';
            	}
             } },
            /* { display: '当前审核流程点', name: 'curAuditPoint', width: '10%', render: function (rowdata, index, value) {
            	if (value == 1) {
            		return '<span title="' + '待采购主管处理' + '">' + '待采购主管处理' + '</span>';
            	}else if (value == 99) {
            		return '<span title="' + '已结束流程' + '">' + '已结束流程' +'</span>';
            	} else {
            		return '';
            	}
            } },  */           
            { display: '审核状态', name: 'auditResult', render: function (rowdata, rowindex, value) {
            	if (value == 0) {
            		return '未审核';
            	} else if (value == 1) {
            		return '审核通过';
            	}else if(value == 2){
            		return '审核拒绝';
            	}else{
            		return '未审核';
            	}
            } },
            { display: '审核时间', name: 'lastAuditTime'},
            /* { display: '操作',width:'15%', isSort: false, render: function (rowdata, rowindex, value){
            	
             	if(rowdata.status ==1){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", 2)'>详情</a>&nbsp;";
             		 h += "<a href='javascript:Storage(\"" + rowdata.puNo + "\", 3)'>出库</a>";
             	}else if(rowdata.status ==2){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", 2)'>详情</a>&nbsp;";
             	}else if(rowdata.status ==3){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", 2)'>详情</a>&nbsp;";
             	}else if(rowdata.status ==4){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", 2)'>详情</a>&nbsp;";
            	}else{
               	 var h = "<a href='javascript:deletePurchase(" + rowindex + ")'>作废</a> "; 
               	     h += "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", 2)'>详情</a>&nbsp;";
               	     h += "<a href='javascript:toPoAudit(" + rowindex + ")'>审核</a>&nbsp;"; 
               	
             	}
                return h;
            	}
            } */
			{ display: '操作', isSort: false,width: '10%', render: function (rowdata, rowindex, value){
            	
             	if(rowdata.status ==1 && rowdata.purType == 1){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\",\"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
             		 h += "<a href='javascript:Storage(\"" + rowdata.puNo + "\", 3)'>退货出库</a>";
             	}else if(rowdata.status ==1 && rowdata.purType == 2){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
             		 h += "<a href='javascript:Storage(\"" + rowdata.puNo + "\", 3)'>换货出库</a>";
             	}else if(rowdata.status ==2){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
             	}else if(rowdata.status ==3){
             		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\",\"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
             	}else if(rowdata.status ==4){
             		var h = "<a href='javascript:StorageIn(\"" + rowdata.puNo + "\", 2)'>换货入库</a>&nbsp;";
             		 h += "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
             	}else if(rowdata.status ==5){
            		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";/*退货*/
            	}else if(rowdata.status ==6){
            		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";/*换货*/
            	}else if(rowdata.status ==7){
            		var h = "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\", \"" + rowdata.prodNo + "\")'>详情</a>&nbsp;";
            	}else{
               	 var h = "<a href='javascript:deletePurchase(" + rowindex + ")'>作废</a> "; 
               	     h += "<a href='javascript:showPoDetail(\"" + rowdata.puNo + "\",\"" + rowdata.prodNo + "\", 2)'>详情</a>&nbsp;";
               	     h += "<a href='javascript:toPoAudit(" + rowindex + ")'>审核</a>&nbsp;"; 
               	
             	}
                return h;
            	}
            }
            ], 
            pageSize:30,
            width: '100%',
            height: '100%',
            dataType: 'server', 
            dataAction: 'server',
            pagesizeParmName: 'pageSize',
            parms: [
                    {name: "puNo", value:$("#puNo").val()},
                    {name: "creater", value:$("#creater").val()},
                    {name: "status", value:$("#status").val()},
                    {name: "commodityName", value:$("#commodityName").val()}
                    
            	],
            url: "ajaxToPoList.do",
            toolbar: toolbar
        });
    });
    var toolbar = '';
    toolbar = {
        	items: [
        			{ text: "新增采购退换货单", click: addPurchase, icon: "add" }
            		]
           		 };
    
    var toolbar;
    var roles = new Array();
    '<c:forEach items="${roleVos}" var="item">';
    roles.push('${item.roleCode}');
    '</c:forEach>';
    
    var rpm = 0;
	if (roles.length > 0) {
		var ex = [];
		var add = [];
		var items = [];
		for(var i=0; i<roles.length; i++) {
			//商品专员管理员
       		if(roles[i] == 'GOOD_PERSON' || roles[i] == 'SYSTEM_ADMIN'){
    			add = [{ text: "新增次品",id:"add", click: addCommodity, icon: "add"},{ line: true }];
    		}
    		if (roles[i] == 'GOODS_SUPERVISOR' || roles[i] == 'FINANCIAL_PRINCIPAL'  || roles[i] == 'SYSTEM_ADMIN') {
    			ex = [{text: '导出EXCEL', click: doExportExcel, icon: "print"},{ line: true }];
    		}
    	}
		items = items.concat(ex);
		items = items.concat(add);
		toolbar = {items : items};
	}
    
    /**
     * 采购单详情
     * @param poNo
     */
    function showPoDetail(puNo,prodNo, num) {
    	var title = num == 1 ? "修改采购单":"采购单详情";
    	window.parent.f_addTab(title, title, '../../../manager/purchaseReturn/orders/showPoDetail.do?puNo=' + puNo + '&prodNo=' +prodNo+ '&num=' + num);
    }
    
    /**
     * 修改采购单
     * @param poNo
     */
    function showPoDetailUpdate(puNo, num) {
    	var title = num == 2 ? "修改采购单":"采购单详情";
    	window.parent.f_addTab(title, title, '../../../manager/purchase/orders/showPoDetail_Update.do?puNo=' + puNo + '&num=' + num);
    }
    
    
     /**
     * 修改采购信息
     */
    function updatePurchase(rowindex){
    	 var puNo=grid.getData()[rowindex].puNo;
    	 var url = basePath+'/manager/purchase/orders/to_update_purchase.do?puNo='+puNo;
          url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
    	  window.parent.f_addTab('修改采购单','修改采购单',url);
    }
    
    /**
     * 新增采购退货信息
     */
    function addPurchase(){
    		var url=basePath+'/manager/purchaseReturn/orders/to_add_purchaseReturn.do';
        	url+="?pTabid="+WIN_TAB.getSelectedTabItemID();
        	window.parent.f_addTab('新增采购退换货','新增采购退换货',url);
    }
    
    /**
     * 删除次品信息
     */
    function deletePurchase(rowindex) {
    	var id=grid.getData()[rowindex].id;
    	$.ligerDialog.confirm('请确认是否作废?',
    		function(yes) {if (yes) {
    			$.post(
    					basePath+ '/manager/purchaseReturn/orders/to_delete_purchaseReturn.do',
    					{id : id},
    					function(data) {
    						if (data == 'success') {
    							window.parent.f_tip('作废成功');
    							window.location.reload();
    						} else if (data == 'fail') {
    							window.parent.f_tip('作废失败');
    						}else{
    							window.parent.f_tip(data);
    						};
    					}
    			);
    		};
    	});
    }
    
    
    /**
     * 采购
     */
    function purchaselist(rowindex) {
    	var id=grid.getData()[rowindex].id;
    	$.ligerDialog.confirm('请确认是否采购?',
    		function(yes) {if (yes) {
    			$.post(
    					basePath+ '/manager/purchase/orders/to_good_purchase.do',
    					{id : id},
    					function(data) {
    						if (data == 'success') {
    							window.parent.f_tip('采购成功');
    							window.location.reload();
    						} else if (data == 'fail') {
    							window.parent.f_tip('采购失败');
    						}else{
    							window.parent.f_tip(data);
    						};
    					}
    			);
    		};
    	});
    }
    
    /**
     * 采购单审核
     * @param poNo
     */
    
    function toPoAudit(rowindex){
   	 var puNo=grid.getData()[rowindex].puNo;
     var tabId = window.top.tab.getSelectedTabItemID();
   	 var url = basePath+'/manager/purchaseReturn/orders/toPoAudit.do?puNo='+puNo;
          url+="&pTabid="+WIN_TAB.getSelectedTabItemID();
   	  window.parent.f_addTab("采购审核",'采购审核',url);
   }
    
    
     /**
      * 退货出库
      * @param puNo
      */
     function Storage(puNo, num) {
     	var title = num == 1 ? "采购退货单":"采购退货单出库";
      	var tabId = window.top.tab.getSelectedTabItemID();
   	    var url = basePath+'/manager/purchaseReturn/orders/AddStockOutForPurchase.do?puNo=' + puNo+'&tabId='+tabId;
     	window.parent.f_addTab(title, title, url);
     }
     
     /**
      * 换货出库
      * @param puNo
      */
     function Storage(puNo, num) {
     	var title = num == 1 ? "采购换货单":"采购换货单出库";
      	var tabId = window.top.tab.getSelectedTabItemID();
   	    var url = basePath+'/manager/purchaseReturn/orders/AddStockOutForPurchase.do?puNo=' + puNo+'&tabId='+tabId;
     	window.parent.f_addTab(title, title, url);
     }
     
     /**
      * 换货入库
      * @param puNo
      */
     function StorageIn(puNo, num) {
     	var title = num == 1 ? "采购单":"采购单入库";
      	var tabId = window.top.tab.getSelectedTabItemID();
   	    var url = basePath+'/manager/purchaseReturn/orders/AddStockInForPurchaseReturn.do?tabId=' + tabId +'&puNo=' + puNo;
     	window.parent.f_addTab(title, title, url);
     }
    
</script>
</body>
</html>